package com.xxx.video.main.presenters;

import android.content.Context;
import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.xxx.video.R;
import com.xxx.video.commen.beans.BaseBean;
import com.xxx.video.commen.presenters.BasePresenter;
import com.xxx.video.commen.utils.ResponseUtils;
import com.xxx.video.commen.utils.StringUtils;
import com.xxx.video.commen.utils.ToastUtils;
import com.xxx.video.main.beans.VideoDetailsBean;
import com.xxx.video.network.listeners.CommonResponseListener;
import com.xxx.video.network.utils.NetWorkUtils;

public class VideoDetailsPresenter extends BasePresenter<IVideoDetailsView> {

    public VideoDetailsPresenter(@NonNull Context context, IVideoDetailsView baseView) {
        super(context, baseView);
    }

    /**
     * get content info
     *
     * @param videoId video id
     */
    public void getContentInfo(String videoId) {
        NetWorkUtils.getInstance().getContentInfo(videoId, new CommonResponseListener<VideoDetailsBean>() {
            @Override
            public void onSuccess(VideoDetailsBean successOb, String result) {
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().initData2View(successOb);
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {
                if (getBaseView() != null) {
                    getBaseView().showRootLayoutStatus(3);
                }
            }
        });

    }


    /**
     * comment
     */
    public void comment(String videoId) {
        String commentContent = getBaseView() == null ? "" : getBaseView().getComment();
        if (TextUtils.isEmpty(commentContent)) {
            ToastUtils.showError(StringUtils.getInstance().getString(R.string.tip_comment_can_not_empty));
            return;
        }
        NetWorkUtils.getInstance().comment(videoId, commentContent, new CommonResponseListener<BaseBean>() {

            @Override
            public void onSuccess(BaseBean successOb, String result) {
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().addCommentSuccess();
                        getBaseView().clearComment();
                        ToastUtils.showSuccess(StringUtils.getInstance().getString(R.string.tip_comment_success));
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {

            }
        });

    }

    /**
     * add browse
     *
     * @param videoId video id
     */
    public void browse(String videoId) {
        NetWorkUtils.getInstance().browse(videoId, String.valueOf(0),
                new CommonResponseListener<BaseBean>() {

                    @Override
                    public void onSuccess(BaseBean successOb, String result) {

                    }

                    @Override
                    public void onFailure(Object failureObj) {

                    }
                });

    }

    /**
     * add play
     *
     * @param videoId video id
     */
    public void play(String videoId,long startTime) {
        NetWorkUtils.getInstance().play(videoId, String.valueOf(0),startTime,
                new CommonResponseListener<BaseBean>() {

                    @Override
                    public void onSuccess(BaseBean successOb, String result) {

                    }

                    @Override
                    public void onFailure(Object failureObj) {

                    }
                });
    }

}
